<template>
  <div class="toolbar-box">
    <el-button-group>
      <el-button v-for="(toolbar,index) in toolbarList" :key="index" :type="toolbar.type" :icon="toolbar.icon"
                 @click="getButtonType(toolbar.event)">{{ $t(toolbar.msg) }}
      </el-button>
    </el-button-group>
  </div>
</template>

<script>
  import ListToolBar from '@/components/common/ListToolbar'

  export default {
    name: 'listtool',
    props: {
      appendButton: {
        type: Array,
        default () {
          return []
        }
      },
      authority: {
        type: Number,
        default () {
          return 31
        },
      }
    },
    data () {
      return {
        listToolbarType: [{
          type: 'primary',
          icon: 'plus',
          msg: 'Plus',
          event: 'add'
        }, {
          type: 'primary',
          icon: 'edit',
          msg: 'Edit',
          event: 'edit'
        }, {
          type: 'primary',
          icon: 'delete',
          msg: 'Delete',
          event: 'delete'
        }, {
          type: 'primary',//打印
          icon: 'print',
          msg: 'Print',
          event: 'print'
        }, {
          type: 'primary',//导出
          icon: 'view',
          msg: 'Load',
          event: 'load'
        }],
        toolbarList: []
      }
    },
    created () {
      var i = 0
      var s
      let len = this.listToolbarType.length
      this.toolbarList = []
      var m = parseInt(this.authority)
      for (i = 0; i < len; i++) {
        s = m & (1 << i)
        if (s != 0) {
          this.toolbarList.push(this.listToolbarType[i])
        }
      }
      if (this.appendButton.length > 0) {
        this.appendButton.forEach(val => this.toolbarList.push(val))
      }
    },
    methods: {
      getButtonType (type) {
        let _this = this
        this.$emit('getCommandClick', type)
      },
    }
  }
</script>

<style scoped>
  .toolbar-box {
    border: 1px solid #20A0FF;
    background-color: #20A0FF;
  }
</style>
